﻿document.writeln("    <div id=\"floatBox\" class=\"floatBox\">");
document.writeln("        <div class=\"title\">");
document.writeln("            <h4>");
document.writeln("                通知");
document.writeln("            <\/h4>");
document.writeln("            <h5>");
document.writeln("                <img id=\"ajaxloadimg\" style=\"display: none;\" alt=\"ajax-loading\" src=\"\/images\/popwin_loading.gif\" \/><\/h5>");
document.writeln("            <span>关闭<\/span><\/div>");
document.writeln("        <div class=\"content\">");
document.writeln("            <ul>");
document.writeln("            <\/ul>");
document.writeln("        <\/div>");
document.writeln("    <\/div>");

//-----------开始时弹出通知窗口----------------------------------------

var cookie; //全局
var ajaxflag = true; //是否开启发送功能

//关闭层
var closeDiv = function() {
    $("#floatBox .title span").text("展开").attr("title", "展开");
    setCookie('close');
    getCookie();
    $("#floatBox").animate({
        height: '30px'
    }, 500, 'linear', function() { $("#floatBox .content").hide(); });
}
//展开层，同时发送ajax请求
var openDiv = function() {
    ajaxLoad();
    $("#floatBox .title span").text("关闭").attr("title", "关闭");
    setCookie('open');
    getCookie();
    $("#floatBox").animate({
        height: '200px'
    }, 500, 'linear', function() { $("#floatBox .content").show(); });
}

//开启定不能用这个函数
function divHidden1() {
    $("#floatBox .title span").toggle(openDiv, closeDiv)
}
function divHidden2() {
    $("#floatBox .title span").toggle(closeDiv, openDiv)
}

//手动实现上面的层展开关闭的交互操作
function divHidden() {
    $("#floatBox .title span").click(function() {
        if (cookie == null || cookie == "close") {
            openDiv();
           
        }
        else {
            closeDiv();
        }
    });
}
//读取cookie
function getCookie() {
    cookie = $.cookie('DIVSETING');

}
//设置cookie
function setCookie(seting) {
    var date = new Date();
    date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
    $.cookie('DIVSETING', seting, { path: '/', expires: date });
    return false;
}
//初始窗口状态
function setDivState() {
    if (cookie == null || cookie == "close") {
        $("#floatBox .title span").text("展开").attr("title", "展开");
    } else {
        openDiv();
    }
    divHidden();
}
//设置目标窗口url
function switchWindow(_top, _left, _right, _middle) {
    var top = _top.split("|");
    self.top.frames[0].ShowDiv(top[0], top[1], top[2], top[3], top[4]);
    self.top.frames[1].location.href = _left;
    //self.top.frames[3].location.href = _middle;
}
//打开窗口
function setAjaxWinState() {
    if (cookie == null || cookie == "close") {
        openDiv();
    } else {
        ajaxLoad();
    }
}
//异步获取数据
function getDataByAjax() {
    if (ajaxflag) {
        setAjaxWinState()
    }
}
function ajaxLoad() {
    $.ajax({
        url: "../PopWinHandler.ashx?action=getpopdata",
        type: 'post',
        beforeSend: function(XMLHttpRequest) {
            $('#ajaxloadimg').show();   //用于显示请求进度条
        },
        success: function(data, textStatus) {   //将得到的数值填充到容器
            $('.floatBox .content ul').html("");
            $('.floatBox .content ul').append(data);
        },
        error: function(XMLHttpRequest, textStatus) {
            $('.floatBox .content ul').html("");    //返回失败的错误代码
            $('.floatBox .content ul').text(XMLHttpRequest.responseText);
        },
        complete: function(XMLHttpRequest, textStatus) {   //数据返回后将进度条隐藏
            $('#ajaxloadimg').hide();
        }
    });
}

$(function() {
    ajaxflag = false; //开启定时获取数据
    getCookie();   //获取开启展开或者关闭的cookie
    if (typeof (clearcookie) != "undefined" && clearcookie == true) {
        openDiv();
        divHidden();  //隐藏边框
      
    } else {
        setDivState();
    }
    //设置获取Ajax数据时间用来实现定时刷新功能
//    setInterval("getDataByAjax();", 1000);
});
